package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.ReportUpload;
import com.itheima.service.ReportUploadService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 体检报告上传控制
 */
@RestController
@RequestMapping("/reportUpload")
public class ReportUploadController {

    @Reference
    private ReportUploadService reportUploadService;

    /**
     * 体检报告上传情况分页查询
     *
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findByPage.do")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean) {
        return reportUploadService.findByPage(queryPageBean);
    }

    /**
     * 新增
     *
     * @param reportUpload
     * @return
     */
    @RequestMapping("add.do")
    public Result add(@RequestBody ReportUpload reportUpload) {
        try {
            reportUploadService.add(reportUpload);
            return new Result(true, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加失败");
        }
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @RequestMapping("deleteById.do")
    public Result deleteById(Integer id) {
        try {
            reportUploadService.deleteById(id);
            return new Result(true, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "删除失败");
        }
    }

    @RequestMapping("upload.do")
    public Result upload(Integer id) {
        try {
            reportUploadService.upload(id);
            return new Result(true, "上传成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "上传失败");
        }
    }
}
